package com.ruoyi.swla2.service.impl;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.swla2.bo.TaskDetailBo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.swla2.mapper.TaskDetailMapper;
import com.ruoyi.swla2.domain.TaskDetail;
import com.ruoyi.swla2.service.ITaskDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
/**
 * 任务详情Service业务层处理
 *
 * @author gdqt
 * @date 2025-06-26
 */
@Service
public class TaskDetailServiceImpl extends ServiceImpl<TaskDetailMapper, TaskDetail> implements ITaskDetailService
{
    @Autowired
    private TaskDetailMapper taskDetailMapper;

    /**
     * 查询任务详情
     *
     * @param id 任务详情主键
     * @return 任务详情
     */
    @Override
    public TaskDetail selectTaskDetailById(Long id)
    {

        return taskDetailMapper.selectById(id);
    }

    /**
     * 查询任务详情列表
     *
     * @param taskDetail 任务详情
     * @return 任务详情
     */
    @Override
    public List<TaskDetail> selectTaskDetailList(TaskDetail taskDetail)
    {
        LambdaQueryWrapper<TaskDetail> queryWrapper = new LambdaQueryWrapper<>();
        if(taskDetail.getDeviceId() != null){
            queryWrapper.eq(TaskDetail::getDeviceId,taskDetail.getDeviceId());
        }
        if(taskDetail.getTaskManagementId() != null){
            queryWrapper.eq(TaskDetail::getTaskManagementId,taskDetail.getTaskManagementId());
        }
        if(!StringUtils.isEmpty(taskDetail.getTaskNo())){
            queryWrapper.eq(TaskDetail::getTaskNo,taskDetail.getTaskNo());
        }
        if(!StringUtils.isEmpty(taskDetail.getTaskAddress())){
            queryWrapper.eq(TaskDetail::getTaskAddress,taskDetail.getTaskAddress());
        }
        return taskDetailMapper.selectList(queryWrapper);
    }

    @Override
    public List<TaskDetailBo> listForGJ(TaskDetailBo taskDetailBo) {
        return taskDetailMapper.listForGJ(taskDetailBo);
    }


    /**
     * 新增任务详情
     *
     * @param taskDetail 任务详情
     * @return 结果
     */
    @Override
    public int insertTaskDetail(TaskDetail taskDetail)
    {
        return taskDetailMapper.insert(taskDetail);
    }

    /**
     * 修改任务详情
     *
     * @param taskDetail 任务详情
     * @return 结果
     */
    @Override
    public int updateTaskDetail(TaskDetail taskDetail)
    {
        taskDetail.setUpdateTime(DateUtils.getNowDate());
        return taskDetailMapper.updateById(taskDetail);
    }

    /**
     * 批量删除任务详情
     *
     * @param ids 需要删除的任务详情主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteTaskDetailByIds(Long[] ids)
    {
        return taskDetailMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除任务详情信息
     *
     * @param id 任务详情主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteTaskDetailById(Long id)
    {
        return taskDetailMapper.deleteById(id);
    }
}
